package demo1;

import java.util.LinkedList;
import java.util.Queue;

 class MyQueue {
      Stack s1;
     Stack s2;
    public MyQueue() {
        s1 = new Stack();
        s2 = new Stack();

    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if(!s2.empty()){
            return s2.pop();
        }else {
            while(!s1.empty()){
                int x = s1.pop();
                s2.push(x);
            }

        }
        return s2.pop();

    }

    public int peek() {
        if(!s2.empty()){
            return s2.peek();
        }else {
            while(!s1.empty()){
                int x = s1.pop();
                s2.push(x);
            }

        }
        return s2.peek();


    }

    public boolean empty() {
        return s1.empty() && s2.empty();
    }
}
